SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE  PROCEDURE [dbo].[SP_TCMOVI_BANC_Q13]                        
/*-------------------------------------------------------*/                        
/*---Empresa               OFISIS S.A.                --*/                        
/*---Cliente               CELIMA                     --*/                        
/*---Sistema               Tesoreria                  --*/                        
/*---M¢dulo                Empresa                    --*/                        
/*---Programa              FLUJO DE CAJA REAL SEMANAL (excel)      --*/                        
/*---Script                SP_TCMOVI_BANC_Q03.sql     --*/                        
/*---Nombre SP             SP_TCMOVI_BANC_Q03         --*/                        
/*---Desarrollado por      Reynaldo Menacho Luyo      --*/                        
/*---Fecha Creaci¢n        25/09/2001                 --*/                        
/*---Base Datos            SQL SERVER        --*/                        
/*---Versi¢n               2000                       --*/                        
/*---Invoca a SP                                      --*/                        
/*-------------------------------------------------------*/                        
                        
/*-------------------------------------------------------*/                        
/*---Modificado 1 por           --*/                        
/*---Fecha Modificaci¢n         --*/                         
/*---Detalle Modificaci¢n       --*/                        
/*-------------------------------------------------------*/                        
                        
/*-------------------------------------------------------*/                        
/*---Drop Proc SP_TCMOVI_BANC_Q03                      --*/                        
/*---Grant all on SP_TCMOVI_BANC_Q03 to public         --*/                         
/*---SP_TCMOVI_BANC_Q03 '01', 'DOL', 10, 2001, 11, 2001  --*/                        
/*-------------------------------------------------------*/                        
                        
--EXEC UL_TCMOVI_BANC_Q13 '01', 'WHERE 1 = 1', '', 'U', 'DOL', '2007/01/01', '2007/06/23'               
                      
@ISCO_EMPR Varchar(2),                          
@ISCA_WHER_0001 Varchar(256),                            
@ISCA_WHER_0002 Varchar(256),                       
@ISTI_PRES TD_VC_001,                           
@ISCO_MONE TD_VC_003,                            
@IDFE_OPER_INIC TD_DT_001,                            
@IDFE_OPER_FINA TD_DT_001                
/*,                        
@INNU_MESE_FINA TD_IN_001,                        
@INNU_ANIO_FINA TD_IN_001  */                      
As                        
CREATE TABLE #TWFLUJ_CAJA_SEMA_Q13_1                        
 ( CO_EMPR      varchar(3) NULL,     
   DE_EMPR      varchar(100) NULL,    
   IM_SALD_INIC_PROY numeric(16,4) DEFAULT 0,      
   IM_SALD_INIC_EJEC numeric(16,4) DEFAULT 0,                       
   CO_ARUB varchar(3) NULL ,      
   DE_ARUB varchar(100) NULL ,                     
   CO_RUBR varchar(3) NULL ,      
   DE_RUBR varchar(100) NULL ,                      
   CO_SUBR varchar(3) NULL ,       
   DE_SUBR varchar(100) NULL ,                    
   IM_SE01_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE02_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE03_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE04_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE05_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE06_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE07_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE08_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE09_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE10_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE11_PROY numeric(16,4) DEFAULT 0,                        
   IM_SE12_PROY numeric(16,4) DEFAULT 0,       
   IM_SE01_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE02_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE03_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE04_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE05_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE06_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE07_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE08_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE09_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE10_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE11_EJEC numeric(16,4) DEFAULT 0,                        
   IM_SE12_EJEC numeric(16,4) DEFAULT 0, 
   IM_SE13_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE14_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE15_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE16_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE17_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE18_PROY numeric(16,4) DEFAULT 0,                                       
   IM_SE19_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE20_PROY numeric(16,4) DEFAULT 0,               
   IM_SE21_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE22_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE23_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE24_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE25_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE26_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE27_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE28_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE29_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE30_PROY numeric(16,4) DEFAULT 0,                   
   IM_SE31_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE32_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE33_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE34_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE35_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE36_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE37_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE38_PROY numeric(16,4) DEFAULT 0,                                       
   IM_SE39_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE40_PROY numeric(16,4) DEFAULT 0,                
   IM_SE41_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE42_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE43_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE44_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE45_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE46_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE47_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE48_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE49_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE50_PROY numeric(16,4) DEFAULT 0,                   
   IM_SE51_PROY numeric(16,4) DEFAULT 0,                                    
   IM_SE52_PROY numeric(16,4) DEFAULT 0,    
   IM_SE13_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE14_EJEC numeric(16,4) DEFAULT 0,                    
   IM_SE15_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE16_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE17_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE18_EJEC numeric(16,4) DEFAULT 0,                                       
   IM_SE19_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE20_EJEC numeric(16,4) DEFAULT 0,               
   IM_SE21_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE22_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE23_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE24_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE25_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE26_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE27_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE28_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE29_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE30_EJEC numeric(16,4) DEFAULT 0,                   
   IM_SE31_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE32_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE33_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE34_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE35_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE36_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE37_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE38_EJEC numeric(16,4) DEFAULT 0,                                       
   IM_SE39_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE40_EJEC numeric(16,4) DEFAULT 0,                
   IM_SE41_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE42_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE43_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE44_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE45_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE46_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE47_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE48_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE49_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE50_EJEC numeric(16,4) DEFAULT 0,                   
   IM_SE51_EJEC numeric(16,4) DEFAULT 0,                                    
   IM_SE52_EJEC numeric(16,4) DEFAULT 0,                                                         
   CO_BANC varchar(3) NULL ,                        
   NU_CNTA_BANC varchar(20) NULL ,                        
   DE_CNTA_BANC varchar(100) NULL ,                                            
   TI_DETA_EMPR  varchar(1) NULL ,                      
   TI_DETA_BANC  varchar(2) NULL )                        
                    
                        
DECLARE                        
                        
@VNNU_MESE  TD_IN_001,                        
@VNNU_ANIO  TD_IN_001,                        
@VSNU_MESE  TD_VC_002,                        
@VSNU_ANIO  VARCHAR(4),                        
@VNNU_CONT_MESE TD_IN_001,                        
@VSDE_SELE VARCHAR(6000),                        
@VSCO_EMPR VARCHAR (50),                        
@VSDE_CAMP VARCHAR(7) ,                    
@VSCO_MONE_NACI TD_VC_003,                    
@VSCO_MONE_EXTR TD_VC_003,                  
@VNNU_FACT  NUMERIC(16,4),          
@VNFA_CAMB_MENS  NUMERIC(15,6)                        
                        
 
IF @ISTI_PRES = 'U'                 
 SELECT @VNNU_FACT = 1                                
IF @ISTI_PRES = 'M'                                
 SELECT @VNNU_FACT = 0.001 

                 
EXECUTE SP_TCMOVI_BANC_PROY_Q13 @ISCO_EMPR, @ISCA_WHER_0001, @ISCA_WHER_0002, @ISTI_PRES, @ISCO_MONE, @IDFE_OPER_INIC, 
@IDFE_OPER_FINA  
 
EXECUTE SP_TCMOVI_BANC_EJEC_Q13 @ISCO_EMPR, @ISCA_WHER_0001, @ISCA_WHER_0002, @ISTI_PRES, @ISCO_MONE, @IDFE_OPER_INIC, 
@IDFE_OPER_FINA  
                   
     
IF @ISTI_PRES = 'M'                    
 BEGIN  
  
SELECT T1.CO_EMPR, MAX(T2.DE_NOMB), SUM(ISNULL(T1.IM_SALD_INIC_EJEC,0) ),                            
  T1.CO_ARUB, MAX(T1.DE_ARUB),                             
  T1.CO_RUBR, MAX(T1.DE_RUBR), T1.CO_SUBR, MAX(T1.DE_SUBR),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE01_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE01_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE02_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE02_EJEC,0))),                             
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE03_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE03_EJEC,0))), 
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE04_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE04_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE05_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE05_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE06_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE06_EJEC,0))),                           
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE07_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE07_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE08_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE08_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE09_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE09_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE10_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE10_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE11_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE11_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE12_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE12_EJEC,0))),                
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE13_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE13_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE14_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE14_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE15_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE15_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE16_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE16_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE17_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE17_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE18_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE18_EJEC,0))),                             
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE19_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE19_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE20_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE20_EJEC,0))),               
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE21_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE21_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE22_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE22_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE23_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE23_EJEC,0))), 
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE24_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE24_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE25_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE25_EJEC,0))), 
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE26_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE26_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE27_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE27_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE28_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE28_EJEC,0))),                             
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE29_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE29_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE30_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE30_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE31_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE31_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE32_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE32_EJEC,0))),                 
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE33_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE33_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE34_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE34_EJEC,0))),                             
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE35_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE35_EJEC,0))), 
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE36_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE36_EJEC,0))),                           
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE37_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE37_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE38_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE38_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE39_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE39_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE40_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE40_EJEC,0))),               
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE41_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE41_EJEC,0))), 
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE42_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE42_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE43_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE43_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE44_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE44_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE45_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE45_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE46_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE46_EJEC,0))),                           
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE47_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE47_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE48_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE48_EJEC,0))),                             
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE49_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE49_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE50_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE50_EJEC,0))),                            
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE51_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE51_EJEC,0))),
  CONVERT ( INT, SUM(ISNULL(T1.IM_SE52_PROY,0))), CONVERT ( INT, SUM(ISNULL(T1.IM_SE52_EJEC,0))),                             
   
  T1.CO_BANC, T1.NU_CNTA_BANC, MAX(T1.DE_CNTA_BANC), MAX(T1.TI_DETA_EMPR), MAX(T1.TI_DETA_BANC)                            
                            
FROM #TWFLUJ_CAJA_SEMA_Q13_1  T1, TMEMPR T2                            
WHERE T1.CO_EMPR = T2.CO_EMPR                                     
GROUP BY T1.CO_EMPR, T1.CO_ARUB, T1.CO_RUBR, T1.CO_SUBR, T1.CO_BANC, T1.NU_CNTA_BANC                      
  
 END  
ELSE  
 BEGIN                    
SELECT T1.CO_EMPR, MAX(T2.DE_NOMB), SUM(ISNULL(T1.IM_SALD_INIC_EJEC,0) ),                         
  T1.CO_ARUB, MAX(T1.DE_ARUB),                             
  T1.CO_RUBR, MAX(T1.DE_RUBR), T1.CO_SUBR, MAX(T1.DE_SUBR),                            
  SUM(ISNULL(T1.IM_SE01_PROY,0)), SUM(ISNULL(T1.IM_SE01_EJEC,0)),
  SUM(ISNULL(T1.IM_SE02_PROY,0)), SUM(ISNULL(T1.IM_SE02_EJEC,0)),                             
  SUM(ISNULL(T1.IM_SE03_PROY,0)), SUM(ISNULL(T1.IM_SE03_EJEC,0)), 
  SUM(ISNULL(T1.IM_SE04_PROY,0)), SUM(ISNULL(T1.IM_SE04_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE05_PROY,0)), SUM(ISNULL(T1.IM_SE05_EJEC,0)),
  SUM(ISNULL(T1.IM_SE06_PROY,0)), SUM(ISNULL(T1.IM_SE06_EJEC,0)),                           
  SUM(ISNULL(T1.IM_SE07_PROY,0)), SUM(ISNULL(T1.IM_SE07_EJEC,0)),
  SUM(ISNULL(T1.IM_SE08_PROY,0)), SUM(ISNULL(T1.IM_SE08_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE09_PROY,0)), SUM(ISNULL(T1.IM_SE09_EJEC,0)),
  SUM(ISNULL(T1.IM_SE10_PROY,0)), SUM(ISNULL(T1.IM_SE10_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE11_PROY,0)), SUM(ISNULL(T1.IM_SE11_EJEC,0)),
  SUM(ISNULL(T1.IM_SE12_PROY,0)), SUM(ISNULL(T1.IM_SE12_EJEC,0)),                
  SUM(ISNULL(T1.IM_SE13_PROY,0)), SUM(ISNULL(T1.IM_SE13_EJEC,0)),
  SUM(ISNULL(T1.IM_SE14_PROY,0)), SUM(ISNULL(T1.IM_SE14_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE15_PROY,0)), SUM(ISNULL(T1.IM_SE15_EJEC,0)),
  SUM(ISNULL(T1.IM_SE16_PROY,0)), SUM(ISNULL(T1.IM_SE16_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE17_PROY,0)), SUM(ISNULL(T1.IM_SE17_EJEC,0)),
  SUM(ISNULL(T1.IM_SE18_PROY,0)), SUM(ISNULL(T1.IM_SE18_EJEC,0)),                             
  SUM(ISNULL(T1.IM_SE19_PROY,0)), SUM(ISNULL(T1.IM_SE19_EJEC,0)),
  SUM(ISNULL(T1.IM_SE20_PROY,0)), SUM(ISNULL(T1.IM_SE20_EJEC,0)),               
  SUM(ISNULL(T1.IM_SE21_PROY,0)), SUM(ISNULL(T1.IM_SE21_EJEC,0)),
  SUM(ISNULL(T1.IM_SE22_PROY,0)), SUM(ISNULL(T1.IM_SE22_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE23_PROY,0)), SUM(ISNULL(T1.IM_SE23_EJEC,0)), 
  SUM(ISNULL(T1.IM_SE24_PROY,0)), SUM(ISNULL(T1.IM_SE24_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE25_PROY,0)), SUM(ISNULL(T1.IM_SE25_EJEC,0)), 
  SUM(ISNULL(T1.IM_SE26_PROY,0)), SUM(ISNULL(T1.IM_SE26_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE27_PROY,0)), SUM(ISNULL(T1.IM_SE27_EJEC,0)),
  SUM(ISNULL(T1.IM_SE28_PROY,0)), SUM(ISNULL(T1.IM_SE28_EJEC,0)),                             
  SUM(ISNULL(T1.IM_SE29_PROY,0)), SUM(ISNULL(T1.IM_SE29_EJEC,0)),
  SUM(ISNULL(T1.IM_SE30_PROY,0)), SUM(ISNULL(T1.IM_SE30_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE31_PROY,0)), SUM(ISNULL(T1.IM_SE31_EJEC,0)),
  SUM(ISNULL(T1.IM_SE32_PROY,0)), SUM(ISNULL(T1.IM_SE32_EJEC,0)),                 
  SUM(ISNULL(T1.IM_SE33_PROY,0)), SUM(ISNULL(T1.IM_SE33_EJEC,0)),
  SUM(ISNULL(T1.IM_SE34_PROY,0)), SUM(ISNULL(T1.IM_SE34_EJEC,0)),                             
  SUM(ISNULL(T1.IM_SE35_PROY,0)), SUM(ISNULL(T1.IM_SE35_EJEC,0)), 
  SUM(ISNULL(T1.IM_SE36_PROY,0)), SUM(ISNULL(T1.IM_SE36_EJEC,0)),                           
  SUM(ISNULL(T1.IM_SE37_PROY,0)), SUM(ISNULL(T1.IM_SE37_EJEC,0)),
  SUM(ISNULL(T1.IM_SE38_PROY,0)), SUM(ISNULL(T1.IM_SE38_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE39_PROY,0)), SUM(ISNULL(T1.IM_SE39_EJEC,0)),
  SUM(ISNULL(T1.IM_SE40_PROY,0)), SUM(ISNULL(T1.IM_SE40_EJEC,0)),               
  SUM(ISNULL(T1.IM_SE41_PROY,0)), SUM(ISNULL(T1.IM_SE41_EJEC,0)), 
  SUM(ISNULL(T1.IM_SE42_PROY,0)), SUM(ISNULL(T1.IM_SE42_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE43_PROY,0)), SUM(ISNULL(T1.IM_SE43_EJEC,0)),
  SUM(ISNULL(T1.IM_SE44_PROY,0)), SUM(ISNULL(T1.IM_SE44_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE45_PROY,0)), SUM(ISNULL(T1.IM_SE45_EJEC,0)),
  SUM(ISNULL(T1.IM_SE46_PROY,0)), SUM(ISNULL(T1.IM_SE46_EJEC,0)),                           
  SUM(ISNULL(T1.IM_SE47_PROY,0)), SUM(ISNULL(T1.IM_SE47_EJEC,0)),
  SUM(ISNULL(T1.IM_SE48_PROY,0)), SUM(ISNULL(T1.IM_SE48_EJEC,0)),                             
  SUM(ISNULL(T1.IM_SE49_PROY,0)), SUM(ISNULL(T1.IM_SE49_EJEC,0)),
  SUM(ISNULL(T1.IM_SE50_PROY,0)), SUM(ISNULL(T1.IM_SE50_EJEC,0)),                            
  SUM(ISNULL(T1.IM_SE51_PROY,0)), SUM(ISNULL(T1.IM_SE51_EJEC,0)),
  SUM(ISNULL(T1.IM_SE52_PROY,0)), SUM(ISNULL(T1.IM_SE52_EJEC,0)),                                
  T1.CO_BANC, T1.NU_CNTA_BANC, MAX(T1.DE_CNTA_BANC), MAX(T1.TI_DETA_EMPR), MAX(T1.TI_DETA_BANC)                            
                            
FROM #TWFLUJ_CAJA_SEMA_Q13_1  T1, TMEMPR T2                            
WHERE T1.CO_EMPR = T2.CO_EMPR                                     
GROUP BY T1.CO_EMPR, T1.CO_ARUB, T1.CO_RUBR, T1.CO_SUBR, T1.CO_BANC, T1.NU_CNTA_BANC            
 END  
  
                        
RETURN                  
                        
/********************************* FIN ***********************************/


GO
